home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-10 | 4.8 KB | 225 lines | [TEXT/KAHL] |
- /*
- ** CAboutDirector.cp
- **
- ** About box library
- ** Dialog director class
- **
- ** Copyright © 1993, FrostByte Design / Eric Scouten
- **
- */
-
-
- #include "CAboutDirector.h"
-
- #include <Commands.h>
- #include <TCLUtilities.h>
- #include <CApplication.h>
- #include <CDesktop.h>
- #include <CSwitchboard.h>
- #include <CList.h>
- #include <CDecorator.h>
- #include <CAbstractText.h>
- #include <CButton.h>
- #include <CDecorator.h>
-
- #include "CAboutDialog.h"
-
-
- // TCL global variables
-
- extern CApplication *gApplication;
- extern CDecorator *gDecorator;
- extern CDesktop *gDesktop;
- extern long gSleepTime;
-
-
- // —— construction/destruction ——
-
- /*______________________________________________________________________
- **
- ** IAboutDirector
- **
- ** Initialize the pane. Nothing special here.
- **
- ** DLOGid (short): the dialog’s resource ID
- ** aSupervisor (CDirectorOwner): who owns us (usually the application)
- **
- */
-
- void CAboutDirector::IAboutDirector (short DLOGid, CDirectorOwner *aSupervisor)
-
- {
- CAboutDialog *theDialog;
-
- CDialogDirector::IDialogDirector(aSupervisor);
-
- hasButtons = FALSE;
- expireTicks = 0;
- itsWindow = theDialog = new (CAboutDialog);
- theDialog->IAboutDialog(DLOGid, gDesktop, this);
- gDecorator->CenterWindow(theDialog);
-
- }
-
-
- // —— displaying methods ——
-
- /*______________________________________________________________________
- **
- ** DoAbout
- **
- ** Respond to the About… command. Default behavior is to display a modal dialog box, then
- ** disposes of the dialog & this director object when completed. If you override this method,
- ** ensure that the dialog & director are disposed when the dialog is completed.
- **
- ** killButtons (Boolean): true to eliminate all push buttons from this dialog
- ** (useful as a splash screen)
- ** maxTicks (long): maximum # ticks to display about box; if this is non-zero,
- ** the box closes after maxTicks ticks (useful as a splash screen)
- **
- */
-
- static Boolean AboutDirector_KillButtons (CView *aView, void *targetID)
- {
- if (member (aView, CButton))
- aView->Hide();
- return FALSE;
- }
-
- static Boolean AboutDirector_IsAButton (CView *aView, void *targetID)
- {
- return (member (aView, CButton));
- }
-
- void CAboutDirector::DoAbout (Boolean killButtons, short maxTicks)
-
- {
- CDialog *itsDialog = (CDialog*) itsWindow;
- tGopherInfo gopherInfo;
- Boolean wasLocked;
-
-
- // check to see if there are buttons
-
- hasButtons = FALSE;
- if (killButtons)
- itsDialog->MatchView(&AboutDirector_KillButtons, NULL);
- else {
- if (itsDialog->MatchView(&AboutDirector_IsAButton, NULL))
- hasButtons = TRUE;
- }
-
-
- // set expiration time
-
- if (maxTicks)
- expireTicks = Ticks + maxTicks;
- else
- expireTicks = 0;
-
-
- // enter modal dialog loop
- // (don’t use DoModalDialog because we need custom behaviors)
-
- if (hasButtons) {
- itsDialog->SetDefaultCmd(cmdOK);
- itsDialog->SetModal(kModal);
- }
- itsDialog->Select();
- if (hasButtons)
- DisableTheMenus();
-
-
- // set the initial gopher
-
- itsDialog->FindGophers(&gopherInfo);
- itsGopher = gopherInfo.firstGopher? gopherInfo.firstGopher : itsDialog;
-
- if (member (itsGopher, CAbstractText))
- ((CAbstractText *) itsGopher)->SelectAll(TRUE);
-
- if (active)
- itsGopher->BecomeGopher( TRUE);
-
-
- // run the dialog
-
- dismissCmd = cmdNull;
-
- TRY {
- do {
- if (hasButtons)
- gApplication->Process1Event();
- else
- PseudoModalGetNextEvent();
- if ((expireTicks) && (Ticks >= expireTicks))
- dismissCmd = cmdOK;
- } while (dismissCmd == cmdNull);
- }
- CATCH {
- if (gLastError != kSilentErr)
- ErrorAlert(gLastError, gLastMessage);
- RETRY;
- }
- ENDTRY;
-
-
- // clean out the window so it doesn’t break up into several images
-
- if (itsDialog->itsSubviews) {
- itsDialog->itsSubviews->DisposeAll();
- itsDialog->itsSubviews = NULL;
- }
- itsDialog->Update();
-
- // we’re done…
-
- if (hasButtons)
- EnableTheMenus();
- Dispose();
-
- }
-
-
- /*______________________________________________________________________
- **
- ** PseudoModalGetNextEvent
- **
- ** Watch for events that would signal closing the about box or splash screen. This routine
- ** is a hybrid of CSwitchboard::Process1Event and CSwitchboard::GetNextEvent. Since it
- ** is used for splash screens (i.e. before app init is completed), it can’t respond in the normal
- ** fashion.
- **
- */
-
- #define someEvents mDownMask + keyDownMask + updateMask
-
- void CAboutDirector::PseudoModalGetNextEvent (void)
-
- {
- EventRecord macEvent; // Mac Event to be processed
- Boolean isMyEvent; // should program handle event?
- Point mouseLoc; // mouse location in global coords
-
-
- // grab a mouse-down, key-down, or update event ONLY
-
- if (gSystem.hasWNE)
- isMyEvent = WaitNextEvent(someEvents, &macEvent, gSleepTime, NULL);
- else {
- SystemTask();
- isMyEvent = GetNextEvent(someEvents, &macEvent);
- }
-
-
- // respond ONLY to update events; mouse/key downs cancel the dialog & get discarded
-
- if (isMyEvent) {
- if (macEvent.what == updateEvt)
- gApplication->itsSwitchboard->DispatchEvent(&macEvent);
- else
- dismissCmd = cmdOK;
- }
-
- }
-